clearvars;

% =========================================================================
% 生成1500幅弧状结构图像，弧的个数，板的长宽，弧的位置，弧的强度，弧的角度都是变量
% =========================================================================

% create the computational grid
Nx = 534;  % number of grid points in the x (row) direction
Ny = 268;  % number of grid points in the y (column) direction

% create initial pressure distribution using makeDisc

num_images = 1500; % 要生成的图像数量

for img_idx = 1 : num_images

    % create initial pressure distribution
    source.p0 = zeros(Nx, Ny); % 初始化压力分布为零矩阵

    %num_of_arcs = randi([1, 3], 1, 1);   % 弧的个数是1到3之间的随机数
    num_of_arcs = 1;   

    for arc_idx = 1 : num_of_arcs

        %确保圆全部在矩阵内
        while true
             % 随机生成圆心的位置
            center_of_circle = [randi([100, Nx-50], 1, 1), randi([Ny/2-10, Ny/2+10], 1, 1)]; %  [grid points]
            % 随机生成圆的半径
            disc_radius = randi([80, 130], 1, 1);  % [grid points]
            if center_of_circle(1) - disc_radius > 1 && center_of_circle(1) + disc_radius < Nx && center_of_circle(2) - disc_radius > 1 && center_of_circle(2) + disc_radius < Ny
                break;
            end
        end

        disc_magnitude = randi([150, 250], 1, 1); % 强度是150到250之间的随机数[Pa]
        disc_1 = disc_magnitude * makeDisc(Nx, Ny, center_of_circle(1), center_of_circle(2), disc_radius);  %disc_1

        magnitude2 = disc_magnitude + 5;   %仅为了与disc_1的强度进行区分

        while true
            % disc_2的圆心和半径如何才能切出来一个弧形
            disc_radius2 = disc_radius + randi([0, 20], 1, 1);    % [grid points] 使得第二个圆半径不小于第一个圆半径
            disc_x_pos2 = randi([center_of_circle(1), center_of_circle(1)+disc_radius2], 1, 1);    % [grid points]  
            disc_y_pos2 = randi([Ny/2-10, Ny/2+10], 1, 1); 	% [grid points]
            %确保圆全部在矩阵内
            if disc_x_pos2 - disc_radius2 < 1 || disc_x_pos2 + disc_radius2 > Nx || disc_y_pos2 - disc_radius2 < 1 || disc_y_pos2 + disc_radius2 > Ny
                continue;
            end

            distance_between_centers = sqrt((disc_x_pos2 - center_of_circle(1))^2 + (disc_y_pos2 - center_of_circle(2))^2);
            %弧状结构的条件，两个圆心之间的距离在第二个圆半径和两圆半径之差之间
            if distance_between_centers < disc_radius2 && distance_between_centers > disc_radius2 - disc_radius
                break;
            end
        end

        disc_2 = magnitude2 * makeDisc(Nx, Ny, disc_x_pos2, disc_y_pos2, disc_radius2);
        disc = disc_1 + disc_2;
        disc(disc ~= disc_magnitude) = 0;  % 使用逻辑索引将不等于 disc_magnitude 的元素置为 0

        % 将弧状结构叠加到初始压力分布上
        source.p0 = source.p0 + disc;
    end
    % smooth the initial pressure distribution and restore the magnitude
    source.p0 = smooth(source.p0, true);

    % ==================================================================
    % SAVE RESULTS，需要保存ground-truth图像
    % ==================================================================
    % 定义保存路径和文件名
    filename = sprintf('./ARCS_Dataset/arcs_initial_pressure_%04d.png', img_idx);
    
    % 将 source.p0 的数据范围缩放到 [0, 255] 以便于保存为图像
    scaled_p0 = mat2gray(source.p0);
    
    % 使用 imwrite 函数保存图像
    imwrite(uint8(scaled_p0 * 255), filename);
    
    % =========================================================================
    % VISUALISATION
    % =========================================================================
    % plot the initial pressure and sensor distribution
%     figure;
%     imagesc(scaled_p0);
%     colormap(getColorMap);    
end


% create initial pressure distribution using makeDisc


% % 弧状结构
% disc_magnitude = 20;
% disc_x_pos = 60;    % [grid points] 可以设置为随机位置
% disc_y_pos = 60;  	% [grid points]
% disc_radius1 = 10;    % [grid points]
% disc_1 = disc_magnitude * makeDisc(Nx, Ny, disc_x_pos, disc_y_pos, disc_radius1);
% magnitude2 = 10;
% disc_x_pos2 = 60;    % [grid points]
% disc_y_pos2 = 70; 	% [grid points]
% disc_radius2 = 15;    % [grid points]
% disc_2 = magnitude2 * makeDisc(Nx, Ny, disc_x_pos2, disc_y_pos2, disc_radius2);
% disc = disc_1 + disc_2;
% disc(disc ~= disc_magnitude) = 0;  % 使用逻辑索引将不等于 disc_magnitude 的元素置为 0
% source.p0 = disc;




